<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\BuyJob;

/**
 * BuyJobSearch represents the model behind the search form about `common\models\BuyJob`.
 */
class BuyJobSearch extends BuyJob
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id','issue', 'user_num', 'user_num_real', 'buy_num', 'buy_num_real', 'is_buy_open', 'is_open', 'receipt_time', 'share_time_pre', 'share_time', 'create_time'], 'integer'],
            [['good_id', 'win_user'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = BuyJob::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'user_num' => $this->user_num,
            'user_num_real' => $this->user_num_real,
            'buy_num' => $this->buy_num,
            'buy_num_real' => $this->buy_num_real,
            'is_buy_open' => $this->is_buy_open,
            'is_open' => $this->is_open,
            'receipt_time' => $this->receipt_time,
            'share_time_pre' => $this->share_time_pre,
            'share_time' => $this->share_time,
            'create_time' => $this->create_time,
        ]);

        $query->andFilterWhere(['like', 'good_id', $this->good_id])
            ->andFilterWhere(['like', 'win_user', $this->win_user]);

        return $dataProvider;
    }
}
